#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void function_a(char c);
void function_b(char c);
void function_c(char c);

void display_menu() {
    printf("a) Function A\n");
    printf("b) Function B\n");
    printf("c) Function C\n");
    printf("q) Quit\n");
    printf("Enter a, b, c, or q: ");
}

int main() {
    void (*pf[3])(char) = {function_a, function_b, function_c};
    char ch;

    display_menu();
    while ((ch = getchar()) != 'q') {
        // 清除输入缓冲区
        while (getchar() != '\n') continue;

        switch (ch) {
            case 'a':
                pf[0](ch);
                break;
            case 'b':
                pf[1](ch);
                break;
            case 'c':
                pf[2](ch);
                break;
            default:
                printf("Invalid choice! Please try again.\n");
                break;
        }
        display_menu();
    }
    printf("Done!\n");
    return 0;
}

void function_a(char c) {
    printf("This is function_a, you selected %c\n", c);
}

void function_b(char c) {
    printf("This is function_b, you selected %c\n", c);
}

void function_c(char c) {
    printf("This is function_c, you selected %c\n", c);
}
